package com.geen.tuoke.ui.dialog

import android.content.Context
import androidx.databinding.DataBindingUtil
import com.blankj.utilcode.util.ToastUtils
import com.geen.tuoke.R
import com.geen.tuoke.databinding.DialogAddTagBinding
import com.geen.tuoke.utils.ext.dp2px
import com.geen.tuoke.widget.dialog.DialogViewHolder
import com.geen.tuoke.widget.dialog.XXDialog

/**
 * @Desc 增加标签的弹窗
 */
class DialogAddTag(
    context: Context,
    var onConfirm: (text:String) -> Unit
) : XXDialog(context, R.layout.dialog_add_tag) {

    private var mBinding: DialogAddTagBinding? = null

    init {
        setWidthAndHeight(dp2px(288f), dp2px(145f))
        setCanceledOnTouchOutside(false)
    }


    override fun convert(holder: DialogViewHolder) {
        mBinding = DataBindingUtil.bind(holder.convertView)
        mBinding?.apply {
            ivClose.setOnClickListener {
                dismiss()
            }

            btnSure.setOnClickListener {
                val text = etName.text.toString().trim()
                if (text.isEmpty()) {
                    ToastUtils.showShort("请输入标签名字")
                    return@setOnClickListener
                }
                onConfirm(text)
                dismiss()
            }
        }
    }


}